//评分星数转换
function convertToStarsArray(stars){
  var num=stars.toString().substring(0,1);
  var array=[];
  for(var i=1;i<=5;i++){
    if(i<=num){
      array.push(1)
    }else{
      array.push(0);
    }
  }

  return array;
}


//网络请求
function http(url,callBack) {
  console.log(url)
  wx.request({
    url:url,
    method:'GET',
    header:{
      "Content-Type":"json"
    },
    success:function(res){
      console.log('success',res.data);
      callBack(res.data);
    },
    fail:function(error){
      console.log(error);
    }
  })
}

//主演姓名列表生成
function convertToCastString(casts) {
  var castsjoin="";
  for(var i in casts) {
    castsjoin=castsjoin +casts[i].name+'/';
  }
  return castsjoin.substring(0,castsjoin.length-2);
}


//主演列表生成
function convertToCastInfos(casts) {
  var castsArray=[];
  for(var i in casts){
    var cast={
      img:casts[i].avatars?casts[i].avatars.large:"",
      name:casts[i].name
    }
    castsArray.push(cast);
  }

  return castsArray;
}

module.exports={
  convertToStarsArray:convertToStarsArray,
  http:http,
  convertToCastString: convertToCastString,
  convertToCastInfos: convertToCastInfos

}